package com.hyp.controller;

import com.hyp.pojo.Emp;
import com.hyp.pojo.Product;
import com.hyp.pojo.Result;
import com.hyp.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
public class EmpController {
    @Autowired
    private EmpService empService;

    @GetMapping("/emplist")
    public Result emplist(){
        List<Emp> empList = empService.list();
        return Result.success(empList);
    }


    //查询回显
    @GetMapping("/emplist/{id}")
    public Result getById(@PathVariable Integer id){//@PathVariable获取路径ID
        Emp emp = empService.getById(id);
        return Result.success(emp);
    }
    //更新
    @PutMapping("/emplist")
    public Result update(@RequestBody Emp emp){
        empService.update(emp);
        return Result.success();
    }

    //增加
    @PostMapping("/emplist")
    public Result addSave(@RequestBody Emp emp){
        empService.addSave(emp);
        return Result.success(emp);
    }

    //删除
    @DeleteMapping("/emplist/{id}")
    public Result delete(@PathVariable Integer id){
        empService.delete(id);
        return Result.success();
    }
}
